<%@page import="com.kaishengit.util.DateUtil"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="include/base.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="UTF-8">
	<title>contact</title>
	<link rel="stylesheet" href="../css/bootstrap.min.css" />
	<link rel="stylesheet" href="../css/style.css" />
	<script type="text/javascript" src="js/jquery.js"></script>
	<script type="text/javascript" src="js/time.js"></script>
</head>
<body>
	<div class="container">
		<!--header start-->
		<div class="header">
			<%@ include file="include/top.jsp"  %>
		</div>
		<!--header end-->
		<div class="content">
			<div class="row">
				<div class="contact"><i class="icon-user"></i><a href="">联系人</a></div>
				<div class="span9">
					<div class="list">
						<div class="contactmessage">
							<c:if test="${empty contact }">
								<blockquote>没有联系人</blockquote>
							</c:if>
							<c:if test="${not empty contact}">
								<span style="display:none" id="id">${contact.id }</span>
								<span>${contact.contactName}</span>
										<address>
										<p>${contact.contactCompanyName}</p>
										<small>手机：  </small>${contact.contactMobile}<br/>
										<small>固话：  </small>${contact.contactTel}<br/><br/>
										<small>邮箱：  </small>${contact.contactEmail}<br/>
										<small>地址： </small>${contact.contactAddress}<br/><br/>
										<small>主页： </small><a href="">${contact.contactWebsite}</a><br/>
										<small>微博：</small><a href="">${contact.contactWeibo}</a><br/><br/>
										</address>
								<b>记录</b>
								</c:if>
							<c:forEach items="${recordList}" var="record">
								<blockquote>${record.recordContent}
									<small title="${record.recordCreatetime}" id="${record.id}"></small>
									<script type="text/javascript">
										var name='${employee.name}';//当前登陆者
										var endtime = getNow();
										var starttime = '${record.recordCreatetime}';
										var id='${record.id}';
										var diftime = getTimeDif(starttime,endtime);
										$("#"+id).text(name+diftime);
									</script>
								</blockquote>
							</c:forEach>
							<c:if test="${empty recordList}">
								<blockquote>没有记录
								</blockquote>
							</c:if>
							<a href="showallrecord.jspx?contactid=${contact.id }" class="find">查看所有记录</a>
						</div>
						
					</div>
				</div>
				<div class="span3">
					<a href="addcontact.jspx" class="btn btn-warning"><i class="icon-plus icon-white"></i>添加联系人</a>
					<c:if test="${not empty contacterr }">
							<span style="font-size:10px;color:red">${contacterr}</span>
					</c:if>
					<c:remove var="contacterr" scope="session"/>
					<ul class="contactnote">
					  <c:forEach items="${listContact }" var="contact">
						<li>
						<i class="icon-list-alt"></i><a rel="${contact.id}" class="contactName">${contact.contactName}</a>&nbsp;
						<a href="editcontact.jspx?id=${contact.id }" title="修改"><i class="icon-pencil"></i></a>
						<a href="javascript:;" title="删除" rel="${contact.id}" class="delcontact"><i class="icon-trash"></i></a>
						</li>
					  </c:forEach>
					  <c:if test="${empty listContact }">
					  	<li>还没有联系人</li>
					  </c:if>
					</ul>
				</div>
			</div>
		</div>
		<%@ include file="include/footer.jsp" %>
	</div>
	<script type="text/template" id="template">
			<span>{{name}}</span>
				<address>
				<p>{{companyname}}</p>
				<small>手机：  </small>{{mobile}}<br/>
				<small>固话：  </small>{{tel}}<br/><br/>
				<small>邮箱：  </small>{{email}}<br/>
				<small>地址： </small>{{address}}<br/><br/>
				<small>主页： </small><a href="">{{website}}</a><br/>
				<small>微博：</small><a href="">{{weibo}}</a><br/><br/>
				</address>
				<b>记录</b>
				<div id="record"></div>
				<a href="showallrecord.jspx?contactid={{contactid}}" class="find">查看所有记录</a>
    </script>
    <script type="text/template" id="template2">
		<blockquote>{{recordContent}}
		<small title="{{recordCreatetime}}" id="{{id}}"></small>
	</blockquote>
	</script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
	<script type="text/javascript">
			$(function(){
				//点击联系人显示信息js
				$(".contactName").click(function(){
					$(".contactmessage").html("");
					var id =$(this).attr("rel");
					$.get("showcontact.jspx",{id:id},function(result){
						var id= result["contact"].id;
						var name = result["contact"].contactName;
						var mobile = result["contact"].contactMobile;
						var tel = result["contact"].contactTel;
						var email = result["contact"].contactEmail;
						var address = result["contact"].contactAddress;
						var website = result["contact"].contactWebsite;
						var weibo = result["contact"].contactWeibo;
						var companyname = result["contact"].contactCompanyName;
						
						var recordList = result["recordList"];
						var template = $("#template").html();
						template = template.replace(/{{name}}/g,name).replace(/{{mobile}}/g,mobile).replace(/{{tel}}/g,tel).replace(/{{email}}/g,email).replace(/{{address}}/g,address).replace(/{{website}}/g,website).replace(/{{weibo}}/g,weibo).replace(/{{companyname}}/g,companyname).replace(/{{contactid}}/g,id);
						$(".contactmessage").html(template);
						
						if(recordList.length>0){
							$("#record").html("");
							for(var i=0;i<recordList.length;i++){
								var recordContent = recordList[i].recordContent;
								var recordCreatetime = recordList[i].recordCreatetime;
								var recordId =recordList[i].id;
								var template2 = $("#template2").html();
								template2 = template2.replace(/{{recordContent}}/g,recordContent).replace(/{{recordCreatetime}}/g,recordCreatetime).replace(/{{id}}/g,recordId);
								$("#record").append(template2);
								
								var name='${employee.name}';//当前登陆者
								var endtime = getNow();
								var diftime = getTimeDif(recordCreatetime,endtime);
								$("#"+recordId).text(name+diftime);
							}
						}else{
							$("#record").append("<blockquote>没有记录</blockquote>");
						}
					});
				});
				
				
				//删除联系人
				$(".delcontact").click(function(){
					var contactid = $(this).attr("rel");
					if(window.confirm("确实要删除该联系人吗？")){
						window.location="delcontact.jspx?id="+contactid;
					}
				});
			
			});
				
	</script>
</body>
</html>